package com.example.easycharge.repository;

import com.example.easycharge.entity.Alert;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface AlertRepository extends JpaRepository<Alert,Long> {
    List<Alert> findAll();
    Page<Alert> findAll(Pageable pageable);
    Page<Alert> findAllBySolved(Pageable pageable,boolean solved);
    int countAlertByAlertId(long alertId);
    @Modifying
    @Transactional
    @Query(value = "update Alert alert set alert.solved=true where alert.alertId=:alertId")
    void solveAlert(long alertId);
}
